package com.boot.main.controller;

import com.boot.main.entity.CcomPermission;
import com.boot.main.entity.CcomRole;
import com.boot.main.service.IPermissionService;
import com.boot.main.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/v1/api")
@Api(tags = "权限模块")
public class PermissionController {
    @Resource
    private IPermissionService permissionService;

    @RequestMapping(value="/permissions", method = RequestMethod.GET)
    @ApiOperation(value = "获取权限列表")
    public Object getPermissions(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit, @RequestParam("name") String name){
        return permissionService.getPermissions(page, limit, name);
    }

    @RequestMapping(value="/permission", method = RequestMethod.POST)
    @ApiOperation(value = "保存权限")
    public Object savePermission(@RequestBody CcomPermission permission){
        permission.setCreate_time(new Date().getTime());
        return permissionService.savePermission(permission);
    }

    @RequestMapping(value="/permission/{id}", method = RequestMethod.PUT)
    @ApiOperation(value="更新权限")
    public Object updatePermission(@RequestBody CcomPermission permission){
        permission.setCreate_time(new Date().getTime());
        return permissionService.updatePermission(permission);
    }

    @RequestMapping(value="/permission/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value="删除权限")
    public Object deletePermission(@PathVariable long id){
        return permissionService.deletePermission(id);
    }
}
